package edu.osumc.bmi.service.consumer;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import edu.osumc.bmi.soap.schema.User;

public class RunClient {

	public static void main(String[] args) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"applicationContext.xml");
		SoapClient soapClient = (SoapClient) ctx.getBean("soapClient");
		List<User> allUsers = soapClient.getAllUsers();
		System.out.println("All users: ");
		for (User u : allUsers) {
			System.out.println(toString(u));
		}
		User user = new User();
		user.setId(5);
		user.setLoginId("myao");
		user.setFirstName("Ming");
		user.setLastName("Yao");
		System.out.println("Add user: " + toString(user));
		soapClient.addUser(user);
		allUsers = soapClient.getAllUsers();
		System.out.println("All users: ");
		for (User u : allUsers) {
			System.out.println(toString(u));
		}
		user = soapClient.getUser(5);
		System.out.println("Get user: " + toString(user));
		user.setLoginId("mingyao");
		soapClient.updateUser(user);
		allUsers = soapClient.getAllUsers();
		System.out.println("All users: ");
		for (User u : allUsers) {
			System.out.println(toString(u));
		}
		soapClient.deleteUser(5);
		allUsers = soapClient.getAllUsers();
		System.out.println("All users: ");
		for (User u : allUsers) {
			System.out.println(toString(u));
		}
	}

	private static String toString(User user) {
		return "[id=" + user.getId() + ", LoginId=" + user.getLoginId()
				+ ", firstName=" + user.getFirstName() + ", lastName="
				+ user.getLastName() + "]";
	}
}
